package com.example.test;

import java.util.Date;
import java.util.LinkedList;
import java.util.List;

/**
 * TODO: 这里要写注释的!
 */
public class EventStorage {
    private int maxSize;
    private List<Date> storage;
    public EventStorage(){
        this.maxSize= 10;
        this.storage= new LinkedList<>();
    }

    public synchronized void set(){
        while (maxSize==storage.size()){
            try {
                wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        storage.add(new Date());
        System.out.printf("Set %d\n",storage.size());
        notifyAll();
    }

    public synchronized void get(){
        while (storage.size()==0){
            try {
                wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        System.out.printf("Get: %d: %s \n", storage.size(), ((LinkedList<?>)storage).poll());
        notifyAll();

    }
}
